home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TVDMX / FILESHOP.PAS < prev    next >
Pascal/Delphi Source File  |  1994-06-20  |  6KB  |  255 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    FILESHOP  --Buffered Stream Editing Demo    }
  5. {    tvDMX      --data editing project        }
  6. {                            }
  7. {    Copyright (c) 1992,93    Randolph Beck        }
  8. {                P.O. Box  56-0487    }
  9. {                Orlando, FL 32856    }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Program FILESHOP;
  15.  
  16. { This program works like WORKSHOP.PAS, except that it uses data from a
  17.   STREAM instead of in memory.    The object's provisions for error-checking
  18.   are not used but can be expanded by overriding TDmxExpBuf.ErrorFunc().
  19.  
  20.   Modify the strings xInfo and xLabel to change the record structure.  Then
  21.   delete FILESHOP.DAT(if it exists).
  22.  
  23.   See unit file TVDMXBUF.PAS for more information on the TDmxExpBuf object.
  24.  }
  25.  
  26. {$M 16384,8192,655360 }
  27. {$B-,R-,X+,V- }
  28.  
  29. uses  Objects, Drivers, Views, Menus, App, MsgBox,
  30.       RSet, DmxGizma, tvDMX, tvDMXBUF, tvGizma;
  31.  
  32. const
  33.     xLabels    =  ' String Field            +Real         Real      Word   Seg : Ofs ';
  34.     xTemplate    =  ' ssssssssssssssssssss║RRRRRRR.ZZZR|($rr,rrr.zz)|WWWWW ║ HHHH:HHHH ';
  35.  
  36.     Prefix =  'FILESHOP.DAT --from a tvDMX program by R. Beck'#13#10#26;
  37.     { this string is used as a demo file header }
  38.  
  39.  
  40.     InteriorInfo    :  string[length(xTemplate)]    =  xTemplate;
  41.     InteriorHeader    :  string[length(xLabels)]    =  xLabels;
  42.  
  43.     PrefixInfo        :  string[length(Prefix)]    =  Prefix;
  44.  
  45.     cmOpenWin        =  101;
  46.  
  47.  
  48. type
  49.     TRecord    =  RECORD
  50.     A    : string[20];
  51.     B    : real;
  52.     C    : real;
  53.     D    : word;
  54.     E    : pointer;
  55.     end;
  56.  
  57.  
  58.     PDmxInterior  = ^TDmxInterior;
  59.     TDmxInterior  =  OBJECT(TDmxExpBuf)
  60.  
  61.      { see documentation on tvDMX's virtual methods if you wish to
  62.        modify your tvDMX view's behavior  }
  63.  
  64.     end;
  65.  
  66.  
  67.     PDmxStreamWin = ^TDmxStreamWin;
  68.     TDmxStreamWin =  OBJECT(TDmxExpBufWin)
  69.       procedure InitDMX(ATemplate : string;  var AData;
  70.              ALabels, ARecInd  : PDmxLink;
  71.              BSize    : longint);  VIRTUAL;
  72.     end;
  73.  
  74.  
  75.     TAppN    =  OBJECT(TAppA)
  76.     end;
  77.  
  78.     TMyApp    =  OBJECT(TAppN)
  79.       constructor Init;
  80.       destructor  Done;  VIRTUAL;
  81.       procedure HandleEvent(var Event: TEvent);  VIRTUAL;
  82.       procedure InitMenuBar;  VIRTUAL;
  83.       procedure OpenWindow;
  84.       function    OpenFile(var F : TDosStream;  FName : string)  : boolean;
  85.       procedure CloseFile(var F : TDosStream);
  86.     end;
  87.  
  88.  
  89. var
  90.     WorkFile    :  TDosStream;    { could be any TStream derivative }
  91.  
  92.  
  93.   { ══ TDmxInterior ══════════════════════════════════════════════════════ }
  94.  
  95.  
  96.      { see documentation on tvDMX's virtual methods if you wish to
  97.        modify your tvDMX view's behavior  }
  98.  
  99.  
  100.   { ══ TDmxStreamWin ═════════════════════════════════════════════════════ }
  101.  
  102.  
  103. procedure TDmxStreamWin.InitDMX(ATemplate : string;  var AData;
  104.                  ALabels, ARecInd : PDmxLink; BSize : longint);
  105. var  R       : TRect;
  106. begin
  107.   GetExtent(R);
  108.   R.Grow(-1,-1);
  109.   If (ALabels <> nil) then Inc(R.A.Y, 2);
  110.   Insert(New(PDmxInterior, Init(ATemplate, AData, BSize, R,
  111.         ALabels, ARecInd,
  112.         StandardScrollBar(sbHorizontal+ sbHandleKeyboard),
  113.         StandardScrollBar(sbVertical  + sbHandleKeyboard))));
  114.  
  115. end;
  116.  
  117.  
  118.   { ══ TMyApp ════════════════════════════════════════════════════════════ }
  119.  
  120.  
  121. constructor TMyApp.Init;
  122. begin
  123.   TAppN.Init;
  124.  
  125.   If OpenFile(WorkFile, 'FILESHOP.DAT') then
  126.     begin
  127.     OpenWindow;  { open the data window }
  128.     end
  129.    else
  130.     begin
  131.     DisableCommands([cmOpenWin]);
  132.     MessageBox('Error initializing file.', nil, mfError + mfOKButton);
  133.     end;
  134.  
  135. end;
  136.  
  137.  
  138. destructor TMyApp.Done;
  139. begin
  140.   TAppN.Done;
  141.   CloseFile(WorkFile);
  142. end;
  143.  
  144.  
  145. procedure TMyApp.HandleEvent(var Event: TEvent);
  146. begin
  147.   TAppN.HandleEvent(Event);
  148.   If Event.What = evCommand then
  149.     begin
  150.     Case Event.Command of
  151.       cmOpenWin  : OpenWindow;
  152.      else
  153.       Exit;
  154.       end;
  155.     ClearEvent(Event);
  156.     end;
  157. end;
  158.  
  159.  
  160. procedure TMyApp.InitMenuBar;
  161. var  R: TRect;
  162. begin
  163.   GetExtent(R);
  164.   R.B.Y := R.A.Y + 1;
  165.   MenuBar := New(PMenuBar, Init(R, NewMenu(
  166.     NewSubMenu('~F~ileshop', hcNoContext, NewMenu(
  167.       NewItem('~O~pen',    'F4',   kbF4,   cmOpenWin, hcNoContext,
  168.       NewLine(
  169.       NewSoundItem(hcNoContext,
  170.       NewVideoItem(hcNoContext,
  171.       NewLine(
  172.       NewItem('e~X~it',  'Alt-X',  kbAltX, cmQuit,    hcNoContext,
  173.       nil))))))),
  174.     NewSubMenu('~W~indow', hcNoContext, NewMenu(
  175.       NewItem('~S~ize/Move', 'Ctrl-F5', kbCtrlF5, cmResize, hcNoContext,
  176.       NewItem('~Z~oom',      'F5',  kbF5,    cmZoom,    hcNoContext,
  177.       NewItem('~T~ile',      '',    kbNoKey, cmTile,    hcNoContext,
  178.       NewItem('C~a~scade',   '',    kbNoKey, cmCascade, hcNoContext,
  179.       NewItem('~N~ext',      'F6',  kbF6,    cmNext,    hcNoContext,
  180.       NewItem('~P~revious', 'Shift-F6', kbShiftF6, cmPrev, hcNoContext,
  181.       NewItem('~C~lose', 'Alt-F3',  kbAltF3, cmClose,    hcNoContext,
  182.       NewLine(
  183.       NewItem('~U~ser screen', 'Alt-F5',  kbAltF5, cmUserScreen, hcNoContext,
  184.       nil)))))))))),
  185.     nil)))
  186.   ));
  187. end;
  188.  
  189.  
  190. procedure TMyApp.OpenWindow;
  191. var  R    : TRect;
  192. begin
  193.   AssignWinRect(R, length(xLabels) + 2, 0);
  194.  
  195.   { Reminder:  The stream used for WorkFile must already be initialized,
  196.            and be able to read and write data to and from the stream. }
  197.  
  198.   DeskTop^.Insert(ValidView(
  199.     New(PDmxStreamWin, Init(R,
  200.         'Fileshop',
  201.         wnNextAvail,
  202.         InteriorInfo,
  203.         WorkFile,         { TStream-derivative }
  204.         length(PrefixInfo),        { prefix size }
  205.         InteriorHeader,
  206.         10))
  207.     ));
  208. end;
  209.  
  210.  
  211. function  TMyApp.OpenFile(var F : TDosStream;  FName : string)    : boolean;
  212. var  Len : longint;
  213. begin
  214.   With F do
  215.     begin
  216.     Init(FName, stOpen);
  217.     If Status <> stOk then
  218.       begin
  219.       Done;
  220.       Init(FName, stCreate);
  221.       Done;
  222.       Init(FName, stOpen);
  223.       end;
  224.     If Status = stOk then
  225.       begin
  226.       Len := GetSize;
  227.       If Len < length(PrefixInfo) then
  228.     begin
  229.     Seek(0);
  230.     Reset;
  231.     Write(PrefixInfo[1], length(PrefixInfo));
  232.     end;
  233.       end;
  234.     OpenFile := (Status = stOk);
  235.     end;
  236. end;
  237.  
  238.  
  239. procedure TMyApp.CloseFile(var F : TDosStream);
  240. begin
  241.   F.Done
  242. end;
  243.  
  244.  
  245.   { ══════════════════════════════════════════════════════════════════════ }
  246.  
  247. var
  248.     MyApp      :  TMyApp;
  249.  
  250. Begin
  251.   MyApp.Init;
  252.   MyApp.Run;
  253.   MyApp.Done;
  254. End.
  255.